var constant = require('../config/constant.config');

merchantPassedController.$inject = ['$location','merchantService','$scope']
function merchantPassedController($location,merchantService,$scope) {
    $scope.merchants = [];
    $scope.detailMerchant = {};
    $scope.imgUrl = constant.IMG_CONTEXT;

    //init data
    merchantService.findMerchantByStatus(1)
        .then(function(res){
            var rs = res.data;
            if(!rs.result){
                alert('find merchant fail');
            }else {
                $scope.merchants = rs.data;
            }
        });

    //view the merhcant details
    $scope.viewDetail = function(mer){
        $scope.detailMerchant = mer;
    }

    $scope.isBan = function(mer){
        merchantService.updateBan(!mer.ban,mer._id).then(function(res)
            {
                var rs = res.data;
                if(!rs.result){
                    alert('ban merchant fail');
                }else {
                    mer.ban = !mer.ban;
                    alert('ban merchant success!')
                }
            });


    }

    $scope.notBan = function(mer){
        merchantService.updateBan(!mer.ban,mer._id).then(function(res)
        {
            var rs = res.data;
            if(!rs.result){
                alert('notban merchant fail');
            }else {
                mer.ban = !mer.ban;
                alert('notban merchant success!')
            }
        });

    }



}

module.exports = merchantPassedController;